﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import flash.display.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.utils.*;

    public class RoomSlotIsOccupiedCommand extends Command {

		[Inject]
        public var event:RoomSlotEvent;
		[Inject]
        public var roomSlotsModel:RoomSlotsModel;

        override public function execute():void{
            var _local1:int = this.event.id;
            var _local2:Slot = this.roomSlotsModel.getSlotById(_local1);
            if (_local2.isWaitingOrLeavingSlot()){
                return;
            };
            if (_local1 >= 2){
                this.roomSlotsModel.setTopFloor(_local2.floor);
            };
            this.updateRoomSlotModules(_local2);
            this.createOrUpdateRoof(_local2);
            this.createBasement(_local2);
        }
        private function updateRoomSlotModules(_arg1:Slot):void{
            var _local2:SlotModule;
            var _local3:SlotModule;
            _local3 = this.roomSlotsModel.get2x2ModuleOfSlot(_arg1);
            _local2 = this.roomSlotsModel.get4x4ModuleOfSlot(_arg1);
            if ((((_local3.id == 0)) && (_local3.areAllSlotsOccupied()))){
                _local2.isActive = true;
            };
            if (_local2.areAllSlotsOccupied()){
                this.roomSlotsModel.activateNext4x4Module();
            };
        }
        private function createBasement(_arg1:Slot):void{
            var _local2:int = _arg1.id;
            if ((((_local2 < 1)) || ((_local2 > 4)))){
                return;
            };
            var _local3:Object = new Object();
            _local3.id = ("basement" + _local2);
            _local3.linkageId = (GameConstants.BASEMENT + _arg1.id);
            _local3.x = _arg1.position.x;
            var _local4:Number = GameConstants.BASEMENT_HEIGHT;
            _local3.y = -(_local4);
            dispatch(new CreationEvent(CreationEvent.CREATE_BASEMENT, _local3));
        }
        private function createOrUpdateRoof(_arg1:Slot):void{
            var _local2:Object = {};
            var _local3:MovieClip = AssetsLibrary.getMovieClip(GameConstants.ROOF_BROWN_01);
            var _local4:Number = _arg1.position.x;
            var _local5:Number = (_local3) ? _local3.height : 0;
            var _local6:Number = (_arg1.position.y - _local5);
            _local3 = null;
            _local2.id = ("the_roof_is_on_fire" + _arg1.column);
            _local2.linkageId = GameConstants.ROOF_BROWN_01;
            _local2.x = _local4;
            _local2.y = _local6;
            if (_arg1.floor == 0){
                dispatch(new CreationEvent(CreationEvent.CREATE_ROOF_DISPLAY, _local2));
            } else {
                if (_arg1.floor > 0){
                    dispatch(new UpdateDisplayEvent(UpdateDisplayEvent.UPDATE_ROOF_DISPLAY, _local2.x, _local2.y, _local2.id));
                };
            };
        }

    }
}//package net.wooga.pets.controllers 
